<?php
/**
 * Last Form.
 * A singleton class which holds the properties of the last HTML form.
 *
 */
class LastForm {
  /**
   * The singleton instance
   */
  private static $instance;

  /**
   * The module's name
   */
  private $module;

  /**
   * The action's name
   */
  private $action;

  /**
   * The HTTP request method
   */
  private $method;

  /**
   * The construct method
   */
  private function __construct() {
  	$this->module = null;
  	$this->action = null;
  	$this->method = 'POST';
  }

  /**
   * The singleton method
   */
  public static function singleton() {
  	if (!isset(self::$instance)) {
  		$c = __CLASS__;
  		self::$instance = new $c;
  	}

  	return self::$instance;
  }

  /**
   * The _clone method. Prevent users to clone the instance
   */
  public function __clone() {
  	trigger_error('Clone is not allowed.', E_USER_ERROR);
  }

  /**
   * route setter
   */
  public function setRoute($route, $method) {
  	$params = sfContext::getInstance()->getController()->convertUrlStringToParameters($route);
	
  	if($params[0] != '') {
  		$params = sfRouting::getInstance()->getRouteByName($params[0]);
  		$this->module = $params[4]["module"];
  		$this->action = $params[4]["action"];
  	} else {
  		$this->module = $params[1]['module'];
  		$this->action = $params[1]['action'];
  	}

  	$this->method = strtoupper($method);
  }

  /**
   * Module getter
   */
  public function getModule() {
  	return $this->module;
  }

  /**
   * Action getter
   */
  public function getAction() {
  	return $this->action;
  }

  /**
   * Method getter
   */
  public function getMethod() {
  	return $this->method;
  }

}

?>
